/*
 * Wazuh Vulnerability Scanner - Unit Tests
 * Copyright (C) 2015, Wazuh Inc.
 * September 21, 2023.
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General Public
 * License (version 2) as published by the FSF - Free Software
 * Foundation.
 */

#ifndef _OS_SCANNER_TEST_HPP
#define _OS_SCANNER_TEST_HPP

#include "MockDatabaseFeedManager.hpp"
#include "TrampolineGlobalData.hpp"
#include "TrampolineOsDataCache.hpp"
#include "TrampolineRemediationDataCache.hpp"
#include "TrampolineSocketDBWrapper.hpp"
#include "flatbuffers/flatbuffer_builder.h"
#include "flatbuffers/idl.h"
#include "scanOrchestrator/osScanner.hpp"
#include "scanOrchestrator/scanContext.hpp"
#include "gtest/gtest.h"
#include <memory>

using TrampolineScanContext = TScanContext<TrampolineOsDataCache, TrampolineGlobalData, TrampolineRemediationDataCache>;
using ::testing::_;

/**
 * @brief Runs unit tests for OsScanner
 */
class OsScannerTest : public ::testing::Test
{
protected:
    // LCOV_EXCL_START
    OsScannerTest() = default;
    ~OsScannerTest() override = default;
    /**
     * @brief Set the environment for testing.
     *
     */
    void SetUp() override;

    /**
     * @brief Clean the environment after testing.
     *
     */
    void TearDown() override;

    /**
     * @brief Loads the scan context with the necessary data.
     *
     * @param deltaMsg Delta message.
     */
    void loadScanContext(std::string deltaMsg);

    /**
     * @brief Method for scan candidates with the callback.
     *
     * @param candidates CVE candidates.
     * @param cnaName CNA name.
     * @param package Package data.
     * @param callback Callback function.
     */
    void scanCandidates(std::string candidates,
                        const std::string& cnaName,
                        const PackageData& package,
                        const std::function<bool(const std::string& cnaName,
                                                 const PackageData& package,
                                                 const NSVulnerabilityScanner::ScanVulnerabilityCandidate&)>& callback);

    /**
     * @brief Method to store the string remediations in the flatbuffer array.
     *
     * @param remediationsStr Remediations string.
     * @param remediationsFb Remediations flatbuffer.
     */
    void parseRemediations(std::string remediationsStr,
                           FlatbufferDataPair<NSVulnerabilityScanner::RemediationInfo>& remediationsFb);

    // LCOV_EXCL_STOP

    /**
     * @brief Smart pointer to the mock database feed manager.
     *
     */
    std::shared_ptr<MockDatabaseFeedManager> m_spDatabaseFeedManagerMock;
    /**
     * @brief Smart pointer to the scan context.
     *
     */
    std::shared_ptr<TrampolineScanContext> m_spScanContext;
    /**
     * @brief Smart pointer to the flatbuffer parser.
     *
     */
    std::shared_ptr<flatbuffers::Parser> m_spParser;
    /**
     * @brief Smart pointer to the flatbuffer parser for remediations.
     *
     */
    std::shared_ptr<flatbuffers::Parser> m_spRemediationsParser;
};

#endif // _OS_SCANNER_TEST_HPP
